﻿using Corina.DataContext.Service;
using Corina.Datamodel.DataObject;
using Corina.Datamodel.Entities;
using Corina.Enumerations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Corina.DataContext.Master
{
    public class SpecimenKindMaster : MasterBase
    {
        public ResultInfo GetAllItems()
        {
            var items = GetInstance<SpecimenKindService>().GetAllItems(ConnectionString(DatabaseKeys.CORINA_PROD));

            return new ResultInfo(ResultValue.Succeed, items.ToArray());
        }

        public ResultInfo Update(string account, string password, int id, string title)
        {
            ResultValue resultValue = VerifyAccount<ManagerInfo>(account, password);

            if (resultValue == ResultValue.Succeed)
            {
                bool flag = GetInstance<SpecimenKindService>().Update(ConnectionString(DatabaseKeys.CORINA_PROD), id, title);
                if (!flag)
                {
                    resultValue = ResultValue.Failed;
                }
            }

            return new ResultInfo(resultValue);
        }

        public ResultInfo Insert(string account, string password, string title)
        {
            ResultValue resultValue = VerifyAccount<ManagerInfo>(account, password);

            if (resultValue == ResultValue.Succeed)
            {
                resultValue = GetInstance<SpecimenKindService>().Insert(ConnectionString(DatabaseKeys.CORINA_PROD), title);
            }

            return new ResultInfo(resultValue);
        }

        public ResultInfo Remove(string account, string password, int id)
        {
            ResultValue resultValue = VerifyAccount<ManagerInfo>(account, password);

            if (resultValue == ResultValue.Succeed)
            {
                bool flag = GetInstance<SpecimenKindService>().Remove(ConnectionString(DatabaseKeys.CORINA_PROD), id);
                if (!flag)
                {
                    resultValue = ResultValue.Failed;
                }
            }

            return new ResultInfo(resultValue);
        }
    }
}
